package ${package.Controller};

import ${package.Service}.${table.serviceName};
import ${package.Entity}.${entity};
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.util.List;

<#if restControllerStyle>
    import org.springframework.web.bind.annotation.RestController;
<#else>
    import org.springframework.stereotype.Controller;
</#if>
<#if superControllerClassPackage??>
    import ${superControllerClassPackage};
</#if>

/**
* ${table.comment!} 控制器
*/
@RestController
@RequestMapping("<#if package.ModuleName??>/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>${table.entityPath}</#if>")
<#if kotlin>
    class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
    <#if superControllerClass??>
        public class ${table.controllerName} extends ${superControllerClass} {
    <#else>
        public class ${table.controllerName} {
    </#if>

    private  ${table.serviceName} ${table.serviceName?uncap_first};

    /**
    * 新增${entity}
    */
    @PostMapping("/save")
    public Boolean save(@RequestBody ${entity} ${entity?uncap_first}) {
    return ${table.serviceName?uncap_first}.save(${entity?uncap_first});
    }

    /**
    * 删除${entity}
    */
    @DeleteMapping("/delete/{id}")
    public Boolean delete(@PathVariable Long id) {
    return ${table.serviceName?uncap_first}.removeById(id);
    }

    /**
    * 修改${entity}
    */
    @PostMapping("/update")
    public Boolean update(@RequestBody ${entity} ${entity?uncap_first}) {
    return ${table.serviceName?uncap_first}.updateById(${entity?uncap_first});
    }

    /**
    * 主键查询${entity}
    */
    @GetMapping("/{id}")
    public ${entity} findById(@PathVariable Long id) {
    return ${table.serviceName?uncap_first}.getById(id);
    }

    /**
    * 分页查询${entity}
    */
    @GetMapping("/page")
    public Page<${entity}> pageQuery(
    @RequestParam(defaultValue = "1") Integer pageNum,
    @RequestParam(defaultValue = "10") Integer pageSize) {
    return ${table.serviceName?uncap_first}.page(new Page<>(pageNum, pageSize));
    }

    /**
    * 列表查询${entity}
    */
    @GetMapping("/list")
    public List<${entity}> listAll() {
    return ${table.serviceName?uncap_first}.list();
    }
    }
</#if>